﻿using System;
using System.Windows.Forms;

namespace PicGame.Utils
{
    internal static class MSGBox
    {
        private const string MsgTitle = "拼图游戏";

        /// <summary>
        /// OK(IWin32Window owner, string msg, string title)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult OK(IWin32Window owner, string msg, string title)
        {
            if (owner != null)
            {
                var control = owner as Control;

                if (!control.IsDisposed)
                {
                    Func<object> fun = () =>
                    {
                        return MessageBox.Show(owner, msg, title ?? MsgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    };

                    return (DialogResult)control.Invoke(fun);
                }
            }

            return MessageBox.Show(msg, title ?? MsgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        /// <summary>
        /// OK(IWin32Window owner, string msg)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult OK(IWin32Window owner, string msg)
        {
            return OK(owner, msg, null);
        }

        /// <summary>
        /// OK(string msg, string title)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult OK(string msg, string title)
        {
            return OK(null, msg, title);
        }

        /// <summary>
        /// OK(string msg)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult OK(string msg)
        {
            return OK(msg, null);
        }

        /// <summary>
        /// OKCancel(IWin32Window owner, string msg, string title)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult OKCancel(IWin32Window owner, string msg, string title)
        {
            if (owner != null)
            {
                var control = owner as Control;

                if (!control.IsDisposed)
                {
                    Func<object> fun = () =>
                    {
                        return MessageBox.Show(owner, msg, title ?? MsgTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    };

                    return (DialogResult)control.Invoke(fun);
                }
            }

            return MessageBox.Show(msg, title ?? MsgTitle, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
        }

        /// <summary>
        /// OKCancel(IWin32Window owner, string msg)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult OKCancel(IWin32Window owner, string msg)
        {
            return OKCancel(owner, msg, null);
        }

        /// <summary>
        /// OKCancel(string msg, string title)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult OKCancel(string msg, string title)
        {
            return OKCancel(null, msg, title);
        }

        /// <summary>
        /// OKCancel(string msg)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult OKCancel(string msg)
        {
            return OKCancel(msg, null);
        }

        /// <summary>
        /// YesNo(IWin32Window owner, string msg, string title)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult YesNo(IWin32Window owner, string msg, string title)
        {
            if (owner != null)
            {
                var control = owner as Control;

                if (!control.IsDisposed)
                {
                    Func<object> fun = () =>
                    {
                        return MessageBox.Show(owner, msg, title ?? MsgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    };

                    return (DialogResult)control.Invoke(fun);
                }
            }

            return MessageBox.Show(msg, title ?? MsgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        /// <summary>
        /// YesNo(IWin32Window owner, string msg)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult YesNo(IWin32Window owner, string msg)
        {
            return YesNo(owner, msg, null);
        }

        /// <summary>
        /// YesNo(string msg, string title)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult YesNo(string msg, string title)
        {
            return YesNo(null, msg, title);
        }

        /// <summary>
        /// YesNo(string msg)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult YesNo(string msg)
        {
            return YesNo(msg, null);
        }

        /// <summary>
        /// YesNoCancel(IWin32Window owner, string msg, string title)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult YesNoCancel(IWin32Window owner, string msg, string title)
        {
            if (owner != null)
            {
                var control = owner as Control;

                if (!control.IsDisposed)
                {
                    Func<object> fun = () =>
                    {
                        return MessageBox.Show(owner, msg, title ?? MsgTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                    };

                    return (DialogResult)control.Invoke(fun);
                }
            }

            return MessageBox.Show(msg, title ?? MsgTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
        }

        /// <summary>
        /// YesNoCancel(IWin32Window owner, string msg)
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult YesNoCancel(IWin32Window owner, string msg)
        {
            return YesNoCancel(owner, msg, null);
        }

        /// <summary>
        /// YesNoCancel(string msg, string title)
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static DialogResult YesNoCancel(string msg, string title)
        {
            return YesNoCancel(null, msg, title);
        }

        /// <summary>
        /// YesNoCancel(string msg)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static DialogResult YesNoCancel(string msg)
        {
            return YesNoCancel(msg, null);
        }
    }
}